﻿package com.winmastergames.lolgame {
	import com.winmastergames.gameassets.*;
	import com.winmastergames.lolgame.enemys.*;
	import com.winmastergames.lolgame.mapDefault;
	import com.winmastergames.lolgame.player;
	import com.winmastergames.lolgame.enemyDebug;
	import fl.motion.Color;
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.geom.ColorTransform;

	public class gameUtils {
		//==================================================
		//Variables
		//==================================================
		public static var gameState:String = "null";

		//==================================================
		//Make Bullet Function
		//==================================================
		public static function makeBullet(playerRef:MovieClip, levelRef:mapDefault, stageRef:Stage, bulletArrayRef:Array, xLoc:Number, yLoc:Number, bulletSpeed:Number){
			try {
				bulletArrayRef.push(new bullet(xLoc, yLoc, levelRef, playerRef.rotation));
				if (getState() == "ingame"){
					reAddMovieClipStage(stageRef, playerRef); //Add Player MovieClip.
				}
			} catch (e:Error){
			}
		}

		//==================================================
		//Get State
		//==================================================
		public static function getState():String {
			return gameState;
		}

		//==================================================
		//Set State
		//==================================================
		public static function setState(newState:String){
			gameState = newState;
		}

		//==================================================
		//Spawn Enemy Function
		//==================================================
		public static function SpawnEnemy(levelRef:mapDefault, healthBarArrayRef:Array, enemyArrayRef:Array, xLoc:Number, yLoc:Number, hHealth:Number){
			var tempEnemy:enemy = new enemy(xLoc, yLoc, levelRef, hHealth);
			enemyArrayRef.push(tempEnemy);
			healthBarArrayRef.push(new healthBar(tempEnemy, enemyArrayRef[enemyArrayRef.indexOf(tempEnemy)], -25, hHealth));
		}

		//==================================================
		//ReAdd MovieClip From Stage
		//==================================================
		public static function reAddMovieClipStage(movieClip:Stage, childMovieClip:MovieClip){
			var tempMovieClip:Stage = movieClip;
			var tempChildMovieClip:MovieClip = childMovieClip;
			tempMovieClip.removeChild(tempChildMovieClip);
			tempMovieClip.addChild(tempChildMovieClip);
		}

		//==================================================
		//ReAdd MovieClip From MovieClip
		//==================================================
		public static function reAddMovieClipMc(movieClip:MovieClip, childMovieClip:MovieClip){
			var tempMovieClip:MovieClip = movieClip;
			var tempChildMovieClip:MovieClip = childMovieClip;
			tempMovieClip.removeChild(tempChildMovieClip);
			tempMovieClip.addChild(tempChildMovieClip);
		}

		//=================================================
		//Create Level Wall
		//=================================================
		public static function createWall(xLoc:int, yLoc:int, width:int, height:int, colour:uint){
			var tempWall:wallAsset = new wallAsset();
			tempWall.x = xLoc;
			tempWall.y = yLoc;
			tempWall.width = width;
			tempWall.height = height;
			var colorTransform:ColorTransform = tempWall.transform.colorTransform;
			colorTransform.color = colour;
			tempWall.transform.colorTransform = colorTransform;
			engine.st_level_mc.walls.addChild(tempWall);
		}
	}
}